package com.twu.biblioteca.service;

import com.twu.biblioteca.model.bookModel;
import com.twu.biblioteca.model.user;

import java.io.InputStream;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: st
 * Date: 14-4-17
 * Time: 下午3:09
 * To change this template use File | Settings | File Templates.
 */
public class checkOutBook {

   public String checkBookInfo(InputStream in){
       System.out.println("\n Please enter book name.");

       Scanner sc = new Scanner(in);
       String bookName = sc.nextLine();
       return bookName;
   }

   public bookModel[] checkOut(bookModel[] bookList,String bookNameEnter,int customerLen,user[] userList){
       int len = 0;
       boolean exit=false;
       while (len<bookList.length&&bookList[len]!=null&&!bookList[len].getCheckStatus()) {
           if (bookList[len].getBookName().equals(bookNameEnter))
           {
               bookList[len].setCheckStatusTrue();
               userList[customerLen].setBook(bookList[len].getBookName());
               System.out.println("Thank you! Enjoy the book");
               exit=true;
               break;
           }
           len++;
       }
       if (!exit)
           System.out.println("That book is not available.");

       return bookList;
   }
}
